from mytool.database.mssql import MSSQL

ms_mv65 = MSSQL(server='172.23.4.242', user='savm', password='*', database='vc')
ms_mv51 = MSSQL(server='172.16.5.243', user='sa', password='*', database='vcenter')
_vm65 = ms_mv65.query('select NAME, FREE_SPACE from VPXV_DATASTORE')
_vm51 = ms_mv51.query('select NAME, FREE_SPACE from VPXV_DATASTORE')
vm65 = {item[0]: item[1] for item in _vm65}
vm51 = {item[0]: item[1] for item in _vm51}

datastore_map = {
    'vm': ['ST-DB-001', 'ST-DB-002', 'ST-DB-003', 'ST-DB-005', 'ST-DB-006', 'ST-DB-007', 'ST-DB-008', 'ST-DB-009',
           'ST-DB-010', 'ST-DB-012', 'ST-DB-013', 'ST-DB-014', 'ST-DB-015', 'ST-DB-016', 'ST-DB-017', 'ST-DB-018',
           'ST-DB-019', 'ST-DB-020', 'ST-DB-021', 'ST-DB-022', 'ST-DB-023', 'ST-DB-024', 'ST-DB-025', 'ST-DB-026',
           'ST-DB-027', 'ST-DB-028', 'ST-DB-029', 'ST-DB-030', 'ST-DB-031', 'ST-DB-032', 'ST-DB-033', 'ST-DB-034',
           'ST-DB-035', 'ST-DB-036', 'ST-DB-037', 'ST-DB-038', 'ST-DB-039', 'ST-DB-040', 'ST-DB-041', 'ST-DB-042',
           'ST-DB-043', 'ST-DB-044', 'ST-DB-045', 'ST-DB-046', 'ST-DB-047', 'ST-DB-048', 'ST-DB-049', 'ST-DB-050',
           'ST-DB-051', 'ST-DB-052', 'ST-DB-053', 'ST-DB-054', 'ST-DB-055', 'ST-DB-056', 'ST-DB-057', 'ST-DB-058',
           'ST-DB-059', 'ST-DB-060', 'ST-DB-061', 'ST-DB-062', 'ST-DB-064', 'ST-DB-065', 'ST-DB-066', 'ST-DB-067',
           'ST-DB-068', 'ST-DB-069', 'ST-DB-070', 'ST-DB-071', 'ST-DB-072', 'ST-DB-073', 'ST-DB-074', 'ST-DB-075',
           'ST-DB-076', 'ST-DB-077', 'ST-DB-078', 'ST-DB-079', 'ST-DB-080', 'ST-DB-081', 'ST-DB-082', 'ST-DB-083',
           'ST-DB-084', 'ST-DB-085', 'ST-DB-086', 'ST-DB-087', 'ST-DB-088', 'ST-DB-089', 'ST-DB-090', 'ST-DB-091',
           'ST-DB-092', 'ST-DB-093', 'ST-DB-094', 'ST-DB-095', 'ST-DB-096', 'ST-DB-097', 'ST-DB-098', 'ST-DB-099',
           'ST-DB-100', 'ST-DB-101', 'ST-DB-102', 'ST-DB-103', 'ST-DB-104', 'ST-DB-105', 'ST-DB-106', 'ST-DB-107',
           'ST-DB-108', 'ST-DB-109', 'ST-DB-110', 'ST-DB-111', 'ST-DB-112', 'ST-DB-113', 'ST-DB-114', 'ST-DB-115',
           'ST-DB-116', 'ST-DB-117', 'ST-DB-118', 'ST-DB-119', 'ST-DB-120', 'ST-DB-121', 'ST-DB-122', 'ST-DB-123',
           'ST-DB-124', 'ST-DB-125', 'ST-DB-126', 'ST-DB-127', 'ST-DB-128', 'ST-DB-129', 'ST-DB-130', 'ST-DB-131',
           'ST-DB-132', 'ST-DB-133', 'ST-DB-134', 'ST-DB-135', 'ST-DB-136', 'ST-DB-137', 'ST-DB-138', 'ST-DB-139',
           'ST-DB-140', 'ST-DB-141', 'ST-DB-142', 'ST-DB-143', 'ST-DB-144', 'ST-DB-145', 'ST-DB-146', 'ST-DB-147',
           'ST-DB-148', 'ST-DB-149', 'ST-DB-150', 'ST-DB-151', 'ST-DB-152', 'ST-DB-153', 'ST-DB-154', 'ST-DB-155',
           'ST-DB-156', 'ST-DB-157', 'ST-DB-158', 'ST-DB-159', 'ST-DB-160', 'ST-DB-161', 'ST-DB-162', 'ST-DB-163',
           'ST-DB-164', 'ST-DB-165', 'ST-DB-166', 'ST-DB-167', 'ST-DB-168', 'ST-DB-169', 'ST-DB-170', 'ST-DB-171',
           'ST-DB-172', 'ST-DB-173', 'ST-DB-174', 'ST-DB-175', 'ST-DB-176', 'ST-DB-177', 'ST-DB-178', 'ST-DB-179',
           'ST-DB-180', 'ST-DB-181', 'ST-DB-182', 'ST-DB-183', 'ST-DB-184', 'ST-DB-185', 'ST-DB-186', 'ST-DB-187',
           'ST-DB-188', 'ST-DB-189', 'ST-DB-190', 'ST1001', 'ST1002', 'ST1003', 'ST1004', 'ST1005', 'ST1006', 'ST2001',
           'ST2002', 'ST2003', 'ST2004', 'ST2005', 'ST2006', 'ST2007', 'ST2008', 'ST2009', 'ST2010', 'ST2011', 'ST2012',
           'ST2013', 'ST2014', 'ST2015', 'ST2016', 'ST2017', 'ST2018', 'ST2019', 'ST2020', 'ST2021', 'ST2022', 'ST2023',
           'ST2024', 'ST2025', 'ST2026', 'ST2027', 'ST2028', 'ST2029', 'ST2030', 'ST2031', 'ST2032', 'ST2033', 'ST2034',
           'ST2035', 'ST2036', 'ST2037', 'ST2038', 'ST2039', 'ST2040', 'ST2041', 'ST2042', 'ST2043', 'ST2044', 'ST2045',
           'ST2046', 'ST2047'],
    '华为5800V5': ['ST2048', 'ST2049', 'ST2050', 'ST2051', 'ST2052', 'ST2053', 'ST2054', 'ST2055', 'ST2056', 'ST2057',
                 'ST2058', 'ST2059', 'ST2060', 'ST2061', 'ST2062', 'ST2063', 'ST2064', 'ST2065', 'ST2066', 'ST2067',
                 'ST2068', 'ST2069', 'ST2070', 'ST2071', 'ST2072', 'ST2073', 'ST2074', 'ST2075', 'ST2076', 'ST2077',
                 'ST2078', 'ST2079', 'ST2080', 'ST2081', 'ST2082', 'ST2083', 'ST2084', 'ST2085', 'ST2086', 'ST2087',
                 'ST2088', 'ST2089', 'ST2090', 'ST2091', 'ST2092', 'ST2093', 'ST2094', 'ST2095', 'ST2096', 'ST2097',
                 'ST2098', 'ST2099', 'ST2100', 'ST2101', 'ST2102', 'ST2103', 'ST2104'],
    '华为N2000': ['ST3015-NAS.59', 'ST3016-NAS.59'],
    '浪潮': ['ST3001-NAS.50', 'ST3002-NAS.50', 'ST3003-NAS.51', 'ST3004-NAS.51', 'ST3005-NAS.52', 'ST3006-NAS.52'],
    '华为2600V3': ['ST3007-NAS.53', 'ST3008-NAS.53', 'ST3009-NAS.53', 'ST3010-NAS.53', 'ST3011-NAS.55', 'ST3012-NAS.55',
                 'ST3013-NAS.55', 'ST3014-NAS.55'],
    '品高': ['ST4103', 'ST4104'],
}


def get_host():
    pass


def get_datastore(vms):
    result = {}
    unit = 1024 * 1024 * 1024
    for key in datastore_map.keys():
        _sum = 0
        for datastore_name in datastore_map.get(key):
            value = int(vms[datastore_name]) / unit - 100
            if value < 100:
                continue
            _sum += value
        result.setdefault(key, round(_sum / 1024, 2))

    return result


a = get_datastore(vm65)
print(a)
print('lzf-toyou', round(int(vm51['lzf-toyou']) / 1024 / 1024 / 1024 / 1024, 2))